//
//  ZMemuViewController.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/5/18.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

class ZMenuViewController: BaseTRTCViewController {
    
    var indxTap:ResultInt?
    
    var dataList:[String] = [] {
        didSet {
            self.tabView.reloadData()
            self.view.setFrameSize(CGSize.init(width: self.view.bounds.width, height: CGFloat(dataList.count*(22+2))+6+10))
        }
    }
    
    
    override func loadView() {
        let view = NSView.init(frame: NSMakeRect(0, 0, 180, 200))
        view.wantsLayer = true
        view.layer?.backgroundColor = color_dark.cgColor
        view.layer?.cornerRadius = 10
        view.layer?.masksToBounds = true
        self.view = view
    }
    
    override func viewWillAppear() {
        super.viewWillAppear()
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.setupUI()
    }
    
    func setupUI() {
        
        self.view.addSubview(tabView)
        tabView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(NSEdgeInsetsMake(3, 0, 3, 0))
        }
    }
    
    lazy var tabView: ZHTableView = {
        let tab = ZHTableView.init(frame: NSRect.zero)
        tab.wantsLayer  = true
        tab.layer?.backgroundColor = color_dark.cgColor
        tab.delegate = self
        tab.dataSourse = self
        return tab
    }()
}

extension  ZMenuViewController:ZHTableViewDelegate,ZHTableViewDataSource {
    func zh_tableView(_ tableView: ZHTableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataList.count
    }
    
    func zh_tableView(_ tableView: ZHTableView, cellForRowAt indexPath: IndexPath) -> NSView? {
        var cell = tableView.tabView.makeView(withIdentifier: ZHTableViewCell.identifier, owner: self) as? ZHTableViewCell
        if cell == nil {
            cell =  ZHTableViewCell.init(identifier: ZHTableViewCell.identifier)
            cell?.setHover()
        }
        cell?.setBottomLine(isHidden: !(indexPath.item==1))
        cell?.stitle.stringValue = self.dataList[indexPath.item]
        return cell
    }
    
    
    func zh_tableView(_ tableView: ZHTableView, didSelectRowAt indexPath: IndexPath) {
        if indxTap != nil {
            self.indxTap!(indexPath.item)
        }
        Lk.shared.dismiss()
        //self.view.window?.performClose(nil)
    }
    
    func zh_tableView(_ tableView: ZHTableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 22
    }
}

extension ZMenuViewController {
    
}
